package com.group9.controller;

import com.group9.dto.FruitInfosPageParams;
import com.group9.dto.FruitInfosParams;
import com.group9.pojo.FruitInfo;
import com.group9.service.FruitInfosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by QZP on 2020/5/12.
 */
@Controller
@RequestMapping("fruit")
public class FruitInfosController {

    @Autowired
    FruitInfosService fruitInfosService;


//    @RequestMapping("fruitInfos")
//    @ResponseBody
//    public List<FruitInfo> queryByNameAndKind(FruitInfosParams fruitInfosParams){
//     List<FruitInfo> fruitInfos = fruitInfosService.selectByNameAndKind(fruitInfosParams);
//     return  fruitInfos;
//    }

    @RequestMapping("fruitlist")
    @ResponseBody
    public List<FruitInfo> selectAll(){
        List<FruitInfo> fruitInfo = fruitInfosService.selectAll();
        fruitInfo.forEach(System.out::println);
        return fruitInfo;
    }


    @RequestMapping("fruitpage")
    @ResponseBody
    public FruitInfosPageParams<FruitInfo> selectByPage(FruitInfosPageParams fruitInfosPageParams){
        return fruitInfosService.selectByPages(fruitInfosPageParams);
    }

    @RequestMapping("test")
    @ResponseBody
    public Map<String,Object> selectByPage( int pageNum, int pageSize){
        List<FruitInfo> fruitInfos = fruitInfosService.selectByPage(pageNum,pageSize);
        Integer totalSize = fruitInfosService.selectCountSize();
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("fruitInfos",fruitInfos);
        map.put("totalSize",totalSize);
        map.put("pageSize",pageSize);
        map.put("pageNum",pageNum);
        return map;
    }


    @RequestMapping("findbykind")
    @ResponseBody
    public List<FruitInfo> selectByNameAndKind(FruitInfosParams fruitInfosParams){
        return fruitInfosService.selectByNameAndKind(fruitInfosParams);
    }


}
